import React,{useEffect, useState} from "react"
import {Card,Table} from 'antd'
import axios from 'axios'
import { getToken,addKeyFn } from '../../utils/utils'

// 现在你需要得到他的token的取值，然后进行获取，之后在使用get原理
function ActivityList(){
    const [tableData,setTableData] = useState([])
    useEffect(()=>{
        axios.get('/my/activity/activitylist',{
            headers:{
                'Authorization':getToken()
            }
        }).then(res=>{
            const result = JSON.stringify(res.data.data)
            setTableData(addKeyFn(JSON.parse(result)))
        })
    },[])
    const columns = [
        {
            title:'活动序号',
            key:'key',
            dataIndex:'key',
            render:(key)=>{
                return <b>{key}</b>
            }
        },{
            title:'活动标题',
            key:'activityTitle',
            dataIndex:'activityTitle',
            render:(activityTitle)=>{
                return <b>{activityTitle}</b>
            }
        }, {
            title:'活动图片',
            key:'activityPic',
            dataIndex:'activityPic',
            render:(activityPic)=>{
                return (
                    <img style={{width:"50px",height:'50px'}} src={activityPic}/>
                )
            }

        },
        {
            title:'活动时间',
            key:'activityTime',
            dataIndex:'activityTime',
            render:(activityTime)=>{
                return <b>{activityTime}</b>
            }
        },
        {
            title:'活动地点',
            key:'activityAdress',
            dataIndex:'activityAdress',
            render:(activityAdress)=>{
                return <b>{activityAdress}</b>
            }
        }
        ,{
            title:'活动详情',
            key:'activityContent',
            dataIndex:'activityContent',
            render:(activityContent)=>{
                return <textarea style={{border:'white'}}>{activityContent}</textarea>
            }
        }
    ]
    return (
        <div>
            <Card title="活动总览列表">
                <Table 
                    dataSource={tableData}
                    columns={columns}
                    pagination={{pageSize:3}} 
                    rowKey={record=>record.activityId}
                    >
                </Table>
            </Card>
        </div>
    )
}
export default ActivityList